package util
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.ui.Mouse;
	
	public class SimpleButton extends Sprite
	{
		private var label:String;
		private var buttonWidth:Number;
		private var buttonHeight:Number;
		public function SimpleButton(label:String="",width:Number=100)
		{
			super();
			this.label = label;
			this.buttonWidth = width;
			init();
			this.buttonMode = true;
			this.mouseChildren = false;
		}
		
		public function init():void {
			var labelText:TextField = new TextField();
			labelText.text = label;
			labelText.autoSize = "left";
			if(labelText.width>100) {
				labelText.width = this.buttonWidth;
				labelText.wordWrap = true;
			}else {
				buttonWidth = labelText.width;
			}
			this.buttonHeight = labelText.height;
			this.graphics.lineStyle(2,0,.7);
			this.graphics.beginFill(0,.5);
			this.graphics.drawRect(0,0,buttonWidth,labelText.height);
			this.graphics.endFill();
			
			this.addChild(labelText);
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
		}
		
		public function onMouseOver(event:MouseEvent):void {
			this.graphics.clear();
			this.graphics.lineStyle(2,0,.7);
			this.graphics.beginFill(0,.3);
			this.graphics.drawRect(0,0,buttonWidth,buttonHeight);
			this.graphics.endFill();
		}
		
		public function onMouseOut(event:MouseEvent):void {
			this.graphics.clear();
			this.graphics.lineStyle(2,0,.7);
			this.graphics.beginFill(0,.5);
			this.graphics.drawRect(0,0,buttonWidth,buttonHeight);
			this.graphics.endFill();
		}
	}
}